home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_13_02
/
small
/
strstack.cpp
< prev
Wrap
C/C++ Source or Header
|
1994-07-18
|
826b
|
41 lines
/* Listing 2 */
class StrStack {
char * itemPtrs[5U];
unsigned items;
public:
StrStack() { items = 0U; }
int full() { return !(5U - items); }
unsigned depth() { return items; }
int push(char * itemPtr);
char * top()
{ return (items? itemPtrs[items-1] : 0); }
char * pop()
{ return (items? itemPtrs[--items] : 0); }
};
int StrStack::push(char * itemPtr)
{
if (!full() && itemPtr) {
itemPtrs[items++] = itemPtr;
return 1;
}
return 0;
}
#include <iostream.h>
#include <iomanip.h>
main()
{
StrStack ToDo;
ToDo.push("wash car");
ToDo.push("cut grass");
ToDo.push("buy groceries");
ToDo.push("cash paycheck");
while (ToDo.top())
cout << ToDo.pop() << endl;
return 0;
}